<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\we\model;

use think\Model;

class WeFans extends Model
{

    
    /**
     * 获取微信配置信息，需要缓存
     */
    public function info($openid,$field=true){
      
      if (is_numeric($openid)){
        $map['id']=$openid;
      }else{
        $map['openid']=$openid;
      }
      $fans = $this->field($field)->where($map)->find();
     
      return  $fans;
    }

     public function infoForFans($openid,$field=true){
      $fans=$this->info($openid,$field=true);
      if (!$fans) return false;
      $printer=model('printer/PrinterFans')->info($fans['openid'],'balance');

      $message="粉丝信息";
      $message.="\nID：".$fans['id'];
      $message.="\n昵称：".$fans['nickname'];
      if($printer) $message.="\n打印余额：".$printer['balance'];
      return  ['fans'=>$fans,'message'=>$message];
    }

    public function infoForFansByOrder($data){
     $fans = $this->infoForFans($data['before']);
     if (!$fans) return ['message'=>'粉丝不存在，请核对粉丝ID'];
     return ['message'=>$fans['message']]; //空尾巴查询
    }

     public function getAdmins($appid){
      $map['appid']=$appid;
      $map['userid']=['NEQ',''];
     
      $admins=$this->where($map)->select();

      
      return  $admins;
    }




    public function editData($data){

      
      if (isset($data['id'])){
         $res = $this->allowField(true)->where('id',$data['id'])->update($data);
      }else{

         $res = $this->allowField(true)->data($data)->save();
      }
    
      return $res;
    }

  
    

    
}